package com.ruoyi.project.wx.api;


import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bootdo.R;
import com.ruoyi.project.wx.domain.MemberExtractDO;
import com.ruoyi.project.wx.service.MemberExtractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * Created by HP on 2019/6/17.
 */
@Controller
@RequestMapping("/api/extract")
public class ApiExtractController {

    @Autowired
    private MemberExtractService memberExtractService;


    /*
    * 去提现
    * type :微信，支付宝，**银行
    * */
    @ResponseBody
    @RequestMapping("/goExtract")
    public R goExtract(@RequestBody Map<String,Object> paramMap) {
        try{
            if (!paramMap.containsKey("userId") || StringUtils.isBlank(paramMap.get("userId").toString())
                    || !paramMap.containsKey("money") || StringUtils.isBlank(paramMap.get("money").toString())
                    || !paramMap.containsKey("type") || StringUtils.isBlank(paramMap.get("type").toString())
                    || !paramMap.containsKey("code") || StringUtils.isBlank(paramMap.get("code").toString())
                    ) {
                return R.error("参数错误");
            }
            return  memberExtractService.goExtract(paramMap);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("提现失败");
        }
    }

    /*
   * 提现记录
   *
   * */
    @ResponseBody
    @RequestMapping("/getExtractList")
    public R getExtractList(@RequestBody Map<String,Object> paramMap) {
        try{
            if (!paramMap.containsKey("userId") || StringUtils.isBlank(paramMap.get("userId").toString())) {
                return R.error("参数错误");
            }
            PageInfo<MemberExtractDO> list = memberExtractService.getExtractList(paramMap);
            return R.ok().put("data", list);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("查询失败");
        }
    }








}
